package com.game.controller;

import com.game.data.BagData;
import com.game.data.GoodsData;
import com.game.data.RoleData;
import com.game.model.equip.Equip;
import com.game.model.goods.Goods;
import com.game.model.api.GoodsType;
import com.game.model.role.PlayerRole;
import com.game.view.Message;

import java.util.Iterator;
import java.util.Map;

/**
 * @Description:奖励控制器
 **/
public class GoodsController {
    public static void useGoods(Map<Goods,Integer>rewards){
        if (rewards==null)return;
        Iterator<Map.Entry<Goods, Integer>> iterator = rewards.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Goods, Integer> next = iterator.next();
            Goods goods = next.getKey();
            int count = next.getValue();
            useGoods(goods,count);
        }
    }

    public static void useGoods(Goods goods,int count){
        PlayerRole playerRole = ((PlayerRole)RoleData.playerRole);
        //如果是经验，就直接加到人物里去 id为1是经验
        if (goods.getId()==1){
            playerRole.setExp(playerRole.getExp()+count);
        }
        //如果是装备就穿上
        else if(goods.getType()==GoodsType.EQUIP||goods instanceof Equip){
            boolean b = RoleController.putInEquip((Equip) goods);
            if (b){
                Message.success("装备成功");
            }
            //从背包移除
            BagData.bag.removeToBag(goods,1);
        }else {
            Message.error("非使用物品");
        }
    }
    //获取物品信息
    public static Goods getGoods(int id){
        return GoodsData.getGoods(id);
    }
}
